import Vue from "vue";

import Element from "element-ui";
import "element-ui/lib/theme-chalk/index.css";

import "@/assets/styles/index.scss"; // global css
import "./permission"; // permission control
import App from "./App";
import store from "./store";
import router from "./router";
import permission from "./directive/permission";
import "echarts-wordcloud";

import { download } from "@/utils/request";

import "./assets/icons"; // icon

import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import moment from "moment";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  handleTree,
} from "@/utils/ruoyi";
import * as directives from "./directive.js";

import Pagination from "@/components/Pagination";
import CommonList from "@/template/CommonList";
import CommonListGroup from "@/template/CommonListGroup";
import CommonListTabs from "@/template/CommonListTabs";
import CommonInfoDialog from "@/template/CommonInfoDialog";
import CommonEditDialog from "@/template/CommonEditDialog";
import CommonUploadDialog from "@/template/CommonUploadDialog";
import CommonPage from "@/template/CommonPage";
import CommonDetailList from "@/template/CommonDetailList";
import CommonChooseDialog from "@/template/CommonChooseDialog";
import * as filters from "./filters";

import CommonTable from "@/components/CommonTable";
import CommonTabs from "@/components/CommonTabs";
import CommonInfoTable from "@/components/CommonInfoTable";
import CommonInfoTableCell from "@/components/CommonInfoTableCell";
import CommonGroupTitle from "@/components/CommonGroupTitle";
import CommonTree from "@/components/CommonTree";
import CommonInput from "@/components/CommonInput";
import CommonInputInteger from "@/components/CommonInputInteger";
import CommonInputNumber from "@/components/CommonInputNumber";
import TitleCard from "@/components/CommonCard/TitleCard";
import CommonCarouselText from "@/components/CommonCarouselText";
import CommonTableTooltip from "@/components/CommonTableTooltip";
import CommonIntervalButton from "@/components/CommonIntervalButton";
import CommonTableTag from "@/components/CommonTableTag";
import CommonHeader from "@/components/CommonHeader";
import CommonError from "@/components/CommonError";
import CommonAuthorized from "@/components/CommonAuthorized";
import CommonSearchContainer from "@/components/CommonSearchContainer";
import CommonPwdResetInput from "@/components/CommonPwdResetInput";
import CommonPwdInput from "@/components/CommonPwdInput";
import CommonJsonView from "@/components/CommonJsonView";
import CommonSearch from "@/components/CommonSearch";
import CommonMenu from "@/components/CommonMenu";
import CommonMenuItem from "@/components/CommonMenuItem";
import CommonChooseUsersSingle from "@/components/CommonChooseUserSingle";
import CommonMarqueeText from "@/components/CommonMarqueeText";
import CommonDept from "@/components/CommonDept";
import CommonAddDept from "@/components/CommonAddDept";
import CommonEmptyData from "@/components/CommonEmptyData";
import CommonMagnifierView from "@/components/CommonMagnifierView";
import CommonSelect from "@/components/CommonSelect";
import CommonTooltipText from "@/components/CommonTooltipText";
import HTable from "@/components/HTable";

import CommonOptionSpan from "@/components/CommonOptionSpan";
import CommonTimeline from "@/components/CommonTimeline";
// import '@/views/components/icons/svg-icons.js'
import "@/assets/iconfont/iconfont.js";
import "@/assets/iconfont/iconfont.css";

// json编辑器
import CodeEditor from "bin-code-editor";

Vue.use(CodeEditor);

import Vue2OrgTree from "vue2-org-tree";
import "vue2-org-tree/dist/style.css";

Vue.use(Vue2OrgTree);

import VueCron from "vue-cron";

Vue.use(VueCron);

import VueClipboard from "vue-clipboard2";
Vue.use(VueClipboard);

import VueEasyTree from "@wchbrad/vue-easy-tree";
// 样式文件，可以根据需要自定义样式或主题
import "@wchbrad/vue-easy-tree/src/assets/index.scss";

Vue.use(VueEasyTree);

// 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar";

import utils from "@/utils/index.js";
// 工具类 utils类 挂载到vue上
Vue.prototype.utils = utils;

//
Vue.prototype.$bus = new Vue();

// 加载过滤器
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});

// 全局方法挂载
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;
Vue.prototype.$bus = new Vue();
/**
 * 获取数据字段中的label
 * @param {数据字段集合} dict
 * @param {所需要获取label的值} value
 * @param {若为查到返回的参数} def
 */
Vue.prototype.findDictLabel = function (dict, value, def) {
  let item = dict.find((item) => item.value == value);
  return item ? item.label : def || "";
};

/**
 * 全局删除 前 确认提示框
 * @returns {Promise<unknown>}
 */
Vue.prototype.$GlobalDeleteConfirm = (
  message = "是否确认删除数据项?",
  type = "警告"
) => {
  return new Promise((resolve, reject) => {
    Element.MessageBox.confirm(message, type, {
      confirmButtonText: "确定",
      confirmButtonClass: "global-delete-confirm",
      cancelButtonText: "取消",
      cancelButtonClass: "global-delete-cancel",
      type: "warning",
    })
      .then(() => {
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};

/**
 * 全局成功 提示
 * @returns {Promise<unknown>}
 */
Vue.prototype.$GlobalSuccessMessage = (message = "新增/编辑/删除 成功") => {
  Element.Message({
    showClose: true,
    message: message,
    type: "success",
  });
};

/**
 * 全局异常 消息提示
 * @returns {Promise<unknown>}
 */
Vue.prototype.$GlobalErrorMessage = (message = "异常提示!") => {
  Element.Message({
    showClose: true,
    message: message,
    type: "error",
  });
};

/**
 * 全局异常错误提示
 * @returns {Promise<unknown>}
 */
Vue.prototype.$GlobalErrorConfirm = (
  title = "新增/编辑/删除 失败",
  message = "未知异常!",
  confirmButtonText = "确定",
  type = "error"
) => {
  return new Promise((resolve, reject) => {
    Element.MessageBox.confirm(message, title, {
      confirmButtonText: confirmButtonText,
      showCancelButton: false,
      type: type,
    })
      .then(() => {
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};

Vue.prototype.$getTimeStr = (val) => {
  if (val) {
    return moment(val).format("YYYY-MM-DD HH:mm:ss");
  } else {
    return val;
  }
};
Vue.prototype.$getlabel = (key, obj) => {
  if (Object.prototype.toString.call(obj) == "[object Object]" && key + "") {
    return obj[key];
  } else {
    return undefined;
  }
};
Vue.prototype.$getTagType = (key, obj) => {
  if (Object.prototype.toString.call(obj) == "[object Object]" && key + "") {
    return obj[key];
  } else {
    return undefined;
  }
};
// 全局组件挂载
Vue.component("Pagination", Pagination);
Vue.component("RightToolbar", RightToolbar);
Vue.component("CommonList", CommonList);
Vue.component("CommonListGroup", CommonListGroup);
Vue.component("CommonListTabs", CommonListTabs);
Vue.component("CommonTable", CommonTable);
Vue.component("CommonTabs", CommonTabs);
Vue.component("CommonInfoDialog", CommonInfoDialog);
Vue.component("CommonEditDialog", CommonEditDialog);
Vue.component("CommonUploadDialog", CommonUploadDialog);
Vue.component("CommonInfoTable", CommonInfoTable);
Vue.component("CommonInfoTableCell", CommonInfoTableCell);
Vue.component("CommonPage", CommonPage);
Vue.component("CommonDetailList", CommonDetailList);
Vue.component("CommonGroupTitle", CommonGroupTitle);
Vue.component("CommonTree", CommonTree);
Vue.component("CommonInput", CommonInput);
Vue.component("CommonInputInteger", CommonInputInteger);
Vue.component("CommonInputNumber", CommonInputNumber);
Vue.component("TitleCard", TitleCard);
Vue.component("CommonCarouselText", CommonCarouselText);
Vue.component("CommonTableTooltip", CommonTableTooltip);
Vue.component("CommonIntervalButton", CommonIntervalButton);
Vue.component("CommonTableTag", CommonTableTag);
Vue.component("CommonHeader", CommonHeader);
Vue.component("CommonError", CommonError);
Vue.component("CommonAuthorized", CommonAuthorized);
Vue.component("CommonSearchContainer", CommonSearchContainer);
Vue.component("CommonPwdResetInput", CommonPwdResetInput);
Vue.component("CommonPwdInput", CommonPwdInput);
Vue.component("CommonJsonView", CommonJsonView);
Vue.component("CommonSearch", CommonSearch);
Vue.component("CommonMenu", CommonMenu);
Vue.component("CommonMenuItem", CommonMenuItem);
Vue.component("CommonChooseUsersSingle", CommonChooseUsersSingle);
Vue.component("CommonMarqueeText", CommonMarqueeText);
Vue.component("CommonChooseDialog", CommonChooseDialog);
Vue.component("CommonDept", CommonDept);
Vue.component("CommonAddDept", CommonAddDept);
Vue.component("CommonEmptyData", CommonEmptyData);
Vue.component("CommonOptionSpan", CommonOptionSpan);
Vue.component("CommonMagnifierView", CommonMagnifierView);
Vue.component("CommonSelect", CommonSelect);
Vue.component("CommonTimeline", CommonTimeline);
Vue.component("CommonTooltipText", CommonTooltipText);
Vue.component("HTable", HTable);
Vue.use(permission);

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: "small",
});

Vue.use(directives);

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
